Skip to content

add task solution#478

Open
lublubuterbrodi wants to merge 6 commits intomate-academy:masterfrom
lublubuterbrodi:develop
Open

add task solution#478
lublubuterbrodi wants to merge 6 commits intomate-academy:masterfrom
lublubuterbrodi:develop

Conversation

@lublubuterbrodi
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

I am requesting changes because several core checklist requirements are not fully met yet, so the CLI behavior is still too permissive and ambiguous. Your src/app.js correctly copies files, resolves paths, and does nothing when source and destination are identical, and it logs errors with console.error, which aligns with [CHECKLIST ITEM #1], [#2], and [#4]. However, on src/app.js you only check for too few arguments; per [CHECKLIST ITEM #3] you must enforce exactly two positional arguments (source and destination) and exit with a non-zero status when this is not satisfied. Similarly, before copying you need to explicitly verify that the source path refers to a regular file using something like fs.statSync(sourcePath).isFile() and, if not, print a clear error (e.g., Source must be a file) and exit, to ensure you “support only copying files” [CHECKLIST ITEM #3]. You also need to enforce the Node.js ≥ 20 requirement [CHECKLIST ITEMS #5 and #6], either via a runtime check on process.versions.node or via a package.json "engines": { "node": ">=20" } declaration plus a startup check that exits with an error on older runtimes. Finally, when you log any fatal error (bad args, invalid source, copy failure), make sure the process terminates with a non-zero exit code (e.g., process.exit(1)), and confirm that the main entry file is available as app.js at the project root as required [CHECKLIST ITEM #7]. Once these critical behaviors are in place, your solution will align well with the task’s strict CLI and runtime expectations—your current structure is close, you just need these few enforcement steps to fully meet the spec.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

src/app.js Outdated
Comment on lines 10 to 13
if (args.length < 2) {
console.error('Two arguments required: source and destination');

return;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The argument check currently allows calls with more than two arguments (only checks for too few). To strictly support plain copying with no flags (checklist #3), enforce exactly two arguments (e.g., if (args.length !== 2) { console.error('Two arguments required: source and destination'); process.exit(1); }).

Comment on lines +18 to +19
const sourcePath = path.resolve(source);
const destinationPath = path.resolve(destination);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After resolving paths, add an explicit check that the source exists and is a regular file (not a directory). fs.statSync(sourcePath).isFile() can be used; if not a file, console.error('Source must be a file') and exit. This ensures the app supports only copying files (checklist #3) and gives clearer errors than relying on copyFileSync to throw.

@@ -1 +1,32 @@
/* eslint-disable no-console */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The task requires Node.js version 20 or higher (checklist #5/#6), but there's no runtime check or package.json engines enforcement. Add a startup check (inspect process.versions.node) or declare "engines": { "node": ">=20" } in package.json and print an error if the runtime is incompatible.

src/app.js Outdated
Comment on lines 27 to 28
} catch (error) {
console.error(error.message);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You log errors with console.error(...) which meets checklist #4, but the process then continues; consider exiting with a non-zero code after logging errors (e.g., process.exit(1)) so CI/tests detect failures reliably.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

I am requesting changes because several core checklist requirements for the CLI behavior and entry point are not yet met, and these are considered blocking. First, the root app.js currently only does require('./src/app'), but the task requires the main CLI implementation to live in the project-root app.js or at least for this file to perform the Node version check, argument parsing, and error-exit behavior ([CHECKLIST ITEM #7]). Second, there is no runtime Node.js >= 20 enforcement in app.js or src/app.js; you should add a startup check using process.versions.node (and optionally "engines": { "node": ">=20" } in package.json) and call console.error(...) followed by process.exit(1) on older versions ([CHECKLIST ITEMS #5 and #6]). Third, several fatal error paths in src/app.js (invalid argument count, missing source file, non-file source, destination being a directory, copy failures) currently only return after logging; they must all terminate the process with a non-zero exit code (e.g., process.exit(1)) so tests and callers can reliably detect failures ([CHECKLIST ITEM #3]).

To fix this, either move the CLI logic from src/app.js into root app.js, or export helper functions from src/app.js and have root app.js handle: Node version check, argument validation, invoking the copy logic, and calling process.exit(1) on any fatal error. Once those blockers are resolved, the rest of your implementation (path resolution, same-source/dest no-op, and file-only copying) already aligns well with the requirements, so you’ll be in a strong position to pass.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

app.js Outdated
#!/usr/bin/env node
'use strict';

require('./src/app');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the checklist the main app implementation must be available in app.js at the project root. Right now this file only does require('./src/app'). Move the CLI logic into this file (or export functions from src/app and call them here) so app.js is the main entry that implements the required behavior (argument parsing, Node version check, and exiting with non-zero codes on fatal errors). This is a critical requirement (checklist item #7).

@@ -0,0 +1,4 @@
#!/usr/bin/env node

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a runtime Node.js version check here (immediately after the shebang or at startup) to enforce Node.js >= 20. The task requires Node.js v20+; performing a runtime check in the root app.js and exiting with a clear console.error(...) + process.exit(1) on older runtimes is necessary (or include "engines": { "node": ">=20" } in package.json and still do a runtime check to fail fast).

Comment on lines +10 to +13
if (args.length !== 2) {
console.error('Two arguments required: source and destination');

return;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You check the number of arguments but only return on error. Per the checklist (#3) CLI failures must terminate with a non-zero exit code so callers/tests can detect failure — call process.exit(1) after console.error(...).

Comment on lines +29 to +32
} catch (e) {
console.error('Source file does not exist');

return;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When fs.statSync for the source throws you log Source file does not exist but then return. This is a fatal error: after console.error(...) you must exit with a non-zero status (e.g., process.exit(1)) so the process signals failure.

Comment on lines +35 to +38
if (!sourceStat.isFile()) {
console.error('Source must be a file');

return;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You correctly detect non-regular source entries and log Source must be a file, but you only return. The app must support only copying files — treat this as fatal and exit non-zero after logging (checklist #3).

Comment on lines +44 to +47
if (destStat.isDirectory()) {
console.error('Destination must be a file');

return;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the destination path exists and is a directory you log Destination must be a file then return. This should be a fatal error: log with console.error(...) and then process.exit(1) so the CLI properly reports failure.

src/app.js Outdated
Comment on lines 53 to 56
try {
fs.copyFileSync(sourcePath, destinationPath);
} catch (error) {
console.error(error.message);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On copy failure you console.error(error.message) but do not exit. Any fatal copy error must terminate with a non-zero exit code after logging so the process indicates a failure to callers/tests.

@@ -1 +1,60 @@
/* eslint-disable no-console */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The task requires Node.js version >= 20 to be enforced. Add a startup runtime check using process.versions.node (or add "engines": { "node": ">=20" } in package.json and still perform a runtime check) and console.error(...) + process.exit(1) if the runtime is too old.

@@ -1 +1,60 @@
/* eslint-disable no-console */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assignment states the app must be written in app.js at the project root. This file is src/app.js. Either move the implementation into the root app.js or make the root app.js the actual CLI entry that performs the required checks (Node version, args, exits) and then invokes code in src/.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

I am approving your solution as an educational override so you can keep progressing while you strengthen a few important details.

You did a solid job in the project-root app.js: it correctly enforces Node.js ≥ 20 at startup, validates arguments, uses console.error(...) for errors, exits non‑zero on fatal paths, correctly handles same‑path no‑ops, and uses fs.copyFileSync as required. The main issues are in src/app.js: it currently has no Node ≥ 20 runtime check at the top (violating the runtime requirement), and several fatal error paths only console.error(...) and then return instead of exiting with a non‑zero status [CHECKLIST ITEM #X]. For example, when the argument count is invalid, when fs.statSync(sourcePath) throws, when the source is not a file, when the destination is a directory, or when the copy operation fails, you should log the error and then call something like a shared die() helper that wraps console.error(...) and process.exit(1) instead of returning. In addition, src/app.js calls main() unconditionally; to avoid side effects when the file is imported, wrap that call in if (require.main === module) main().

Overall, your core logic and understanding of the requirements are strong—tightening the Node version check and exit behavior in src/app.js will make your implementation fully consistent and robust. Keep up the good work; these are subtle, real‑world details that many developers only master with practice.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Comment on lines +1 to +6
#!/usr/bin/env node
/* eslint-disable no-console */
'use strict';

const fs = require('fs');
const path = require('path');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing Node.js runtime enforcement. The task requires a startup check for Node v20+ that logs with console.error(...) and exits non-zero on older versions — add that at the top of the file (e.g. inspect process.versions.node).

Comment on lines +11 to +14
if (args.length !== 2) {
console.error('Two arguments required: source and destination');

return;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invalid argument count is a fatal error but you console.error(...) then return. Per checklist all fatal error paths must exit with a non-zero code — replace this return with process.exit(1) or call a die() helper.

Comment on lines +28 to +33
try {
sourceStat = fs.statSync(sourcePath);
} catch (e) {
console.error('Source file does not exist');

return;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When fs.statSync(sourcePath) throws you log the error then return. This is a fatal path and must call process.exit(1) after logging so callers/tests can detect failure.

Comment on lines +36 to +39
if (!sourceStat.isFile()) {
console.error('Source must be a file');

return;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the source exists but is not a file you console.error(...) then return. This is a fatal error and must exit with a non-zero code (e.g. process.exit(1)).

Comment on lines +42 to +48
try {
const destStat = fs.statSync(destinationPath);

if (destStat.isDirectory()) {
console.error('Destination must be a file');

return;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If destination exists and is a directory you console.error(...) then return. This should be treated as a fatal error and exit with a non-zero code rather than returning.

Comment on lines +54 to +57
try {
fs.copyFileSync(sourcePath, destinationPath);
} catch (e) {
console.error(e.message);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On copy failure you only console.error(e.message) and do not exit. Copy failure is fatal — log and call process.exit(1) so the process returns a failure status.

}
}

main();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The module executes main() unconditionally. If this file is intended to be imported (or if you also have a project-root app.js), avoid side effects by guarding execution with if (require.main === module) main() or export functions instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants